<?php

class UserMgr {

	private $_db = null;
	
	public function __construct($user = null) {
		$dbHost = $GLOBALS["a.dbHost"];
		$dbMain = $GLOBALS["a.dbMain"];
		$dbUser = $GLOBALS["a.dbUser"];
		$dbPass = $GLOBALS["a.dbPass"];
		$this->_db = new DBG($dbMain, $dbUser, $dbPass, $dbHost);
	}

	public function checkLogin($userName = null, $password = null, $remember = 0) {
		
		$this->_db->select("users", array('loginID' => "$userName", 'activeUser' => 1));
		$recordX = $this->_db->row_array();
		$userX = $recordX["loginID"];
		$passX = $recordX["pass"];
		$saltX = $recordX["salt"];

		if (Security::matchString($password, $passX, $saltX)) {return true;}
		return false;
	}
	
	public function createUser($userName = null, $password = null, $fullName = null){
		$salt = Security::getSalt(32);
		$password = Security::cryptString($password, $salt);
		$dbTable_Users = $GLOBALS["a.dbTable_Users"];
		
		$activeUser = 0;
		if (!$GLOBALS["User"]["RegnApprovalRequired"] && !$GLOBALS["User"]["EmailConfirmationRequired"]) {
			$activeUser = 1;
		}	
		
		$this->_db->insert("$dbTable_Users", 
			array(
				'loginID' => "$userName",
				'pass' => "$password",
				'salt' => "$salt",
				'activeUser' => "$activeUser",
				'fullName' => "$fullName"
			)
		);
		return $this->_db->id();
	}
}

?>